package com.hyts.aop.bean;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.aop.bean
 * author:Libo/Alex
 * create-date:2019-05-15 19:52
 * copyright:libo-hyts-github
 * email:libo2dev@aliyun.com
 * description:此类主要用于: 主要用于承接参数的控制服务功能
 */
public class ProcessArg {

    private Object[] argument;

    private Object result;

    private Object realObject;

    private Method invokeMethod;

    private boolean isExecuted;


    public ProcessArg(Object[] argument) {
        this.argument = argument;
    }

    public ProcessArg(Object result) {
        this.result = result;
    }

    public ProcessArg(Object[] argument, Object result) {
        this.argument = argument;
        this.result = result;
    }

    public Object[] getArgument() {
        return argument;
    }

    public void setArgument(Object[] argument) {
        this.argument = argument;
    }

    public Object getResult() {
        return result;
    }

    public void setResult(Object result) {
        this.result = result;
    }

    public Object getRealObject() {
        return realObject;
    }

    public void setRealObject(Object realObject) {
        this.realObject = realObject;
    }

    public Method getInvokeMethod() {
        return invokeMethod;
    }

    public void setInvokeMethod(Method invokeMethod) {
        this.invokeMethod = invokeMethod;
    }

    public void invoke(){
        try {
            isExecuted = false;
            invokeMethod.invoke(realObject,argument);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }finally {
            isExecuted = true;
        }
    }

    public void invoke(Object[] argument){
        try {
            isExecuted = false;
            invokeMethod.invoke(realObject,argument);
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        } catch (InvocationTargetException e) {
            e.printStackTrace();
        }finally {
            isExecuted = true;
        }
    }

    public boolean isExecuted() {
        return isExecuted;
    }
}
